/*
 * BlockingQueue.h
 *
 *  Created on: 2015年6月13日
 *      Author: vincent
 */

#ifndef BLOCKINGQUEUE_H_
#define BLOCKINGQUEUE_H_

#include "LinkedList.h"
#include <pthread.h>

typedef struct _blocking_queue
{
	unsigned int capacity;
	unsigned char is_destroy;
	LINKED_LIST* item_list;
	pthread_mutex_t* mutex_for_take;
	pthread_mutex_t* mutex_for_take_empty_wait;
	pthread_cond_t* cond_for_take_empty_wait;
	pthread_mutex_t* mutex_for_put;
	pthread_mutex_t* mutex_for_put_full_wait;
	pthread_cond_t* cond_for_put_full_wait;
}BLOCKING_QUEUE;

/**
 * 构造阻塞队列
 */
BLOCKING_QUEUE* blocking_queue_construct(unsigned int capacity);
/**
 * 销毁阻塞队列
 */
int blocking_queue_destroy(BLOCKING_QUEUE* blocking_queue);
/**
 * 从队列中取出元素
 */
int blocking_queue_take(BLOCKING_QUEUE* blocking_queue, void** target);
/**
 * 向队列中放入元素
 */
int blocking_queue_put(BLOCKING_QUEUE* blocking_queue, void* target);

#endif /* BLOCKINGQUEUE_H_ */
